package com.cisystem.system.service.impl;

import com.cisystem.system.domain.FileVerb;
import com.cisystem.system.mapper.FileVerbMapper;
import com.cisystem.system.service.IFileVerbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 文件浏览Service业务层处理
 *
 * @author xxx
 * @date 2024-01-10
 */
@Service
public class FileVerbServiceImpl implements IFileVerbService {
    @Autowired
    private FileVerbMapper fileVerbMapper;

    /**
     * 查询文件浏览
     *
     * @param id 文件浏览主键
     * @return 文件浏览
     */
    @Override
    public FileVerb selectFileVerbById(Long id) {
        return fileVerbMapper.selectFileVerbById(id);
    }

    /**
     * 查询文件浏览列表
     *
     * @param fileVerb 文件浏览
     * @return 文件浏览
     */
    @Override
    public List<FileVerb> selectFileVerbList(FileVerb fileVerb) {

        return fileVerbMapper.selectFileVerbList(fileVerb);
    }

    @Override
    public List<FileVerb> selectFileVerbListGroup(FileVerb fileVerb) {

        return fileVerbMapper.selectFileVerbListGroup(fileVerb);
    }

    /**
     * 新增文件浏览
     *
     * @param fileVerb 文件浏览
     * @return 结果
     */
    @Override
    public int insertFileVerb(FileVerb fileVerb) {
        List<FileVerb> fileVerb1 = fileVerbMapper.selectByEmployeeIdAndFilePath(fileVerb.getEmployeeId(), fileVerb.getFilePath());
        if (CollectionUtils.isEmpty(fileVerb1)) {
            fileVerb.setFirstTime(fileVerb.getReadTime());
        }else{
            fileVerb.setFirstTime(fileVerb1.get(0).getReadTime());
        }
        return fileVerbMapper.insertFileVerb(fileVerb);
    }

    /**
     * 修改文件浏览
     *
     * @param fileVerb 文件浏览
     * @return 结果
     */
    @Override
    public int updateFileVerb(FileVerb fileVerb) {
        return fileVerbMapper.updateFileVerb(fileVerb);
    }

    /**
     * 批量删除文件浏览
     *
     * @param ids 需要删除的文件浏览主键
     * @return 结果
     */
    @Override
    public int deleteFileVerbByIds(Long[] ids) {
        return fileVerbMapper.deleteFileVerbByIds(ids);
    }

    /**
     * 删除文件浏览信息
     *
     * @param id 文件浏览主键
     * @return 结果
     */
    @Override
    public int deleteFileVerbById(Long id) {
        return fileVerbMapper.deleteFileVerbById(id);
    }

    @Override
    public int updateFileVerbStatus(FileVerb fileVerb) {
        return fileVerbMapper.updateFileVerbStatus(fileVerb);
    }
}
